/* REPLICATION MATERIAL

Paper: Crowds and smiles: Visual opportunity structures and the communication of European political leaders during the Covid-19 pandemic
Authors: Moreno Mancosu, Gaetano Scaduto
Apr 8, 2024

REPLICATION FOR
FIG SM1-1
TAB SM1-1 / TAB SM10-2 
*/

cd "PATH"

use "data_repo.dta",clear

logit group_pic c.lrgen i.gndr i.weekend i.cntry c.share_part ///
      i.prepost_pand monthyear_ i.govopp happy, vce(cluster account)

gen final_samp = 1 if e(sample)

********************************************************************************
***** Figure SM1-1
********************************************************************************

preserve
bysort monthyear_ account:egen meanSubs = mean(subscriberCount)
keep monthyear_ account meanSubs
duplicates drop
drop if meanSubs==0
collapse (sum) meanSubs,by(monthyear_)
replace meanSubs = meanSubs/1000000

twoway (line meanSubs monthyear_),xsc(r(0 35)) ///
 xlabel(1 "Mar-19" 8 "Oct-19" 16 "Jun-20" 24 "Feb-21" 32 "Oct-21") xtitle("Month") ///
 ytitle("Average (registered)" "number of followers per months")
graph export "FigureSM1-1.png",replace
restore

********************************************************************************
***** Table SM1-1
********************************************************************************

preserve
tab cntry,gen(country_d)
tab monthyear_,gen(monthyear__d)
tabstat group_pic happy happiness lrgen gndr share_part weekend prepost_pand ///
        deaths_1m_sm govopp favnorm commnorm country_d* monthyear__d* ///
	if final_samp == 1, format(%9.2f) statistics(mean sd min max n) columns(statistics)
restore 


********************************************************************************
***** Table SM2_1
********************************************************************************

preserve
keep country_codes party name_y account_name_IG final_samp
gen nposts = 1
collapse (first) country_codes party name_y (sum) nposts final_samp,by(account_name_IG)
keep if final_samp!=0
order country_codes party name_y account_name_IG nposts
sort country_codes
browse country_codes party name_y account_name_IG nposts
restore

********************************************************************************
***** table SM3-1
********************************************************************************


***mod1

xtmixed happiness c.lrgen i.gndr c.share_part i.weekend i.cntry  ///
        i.prepost_pand i.govopp if final_samp == 1 || account:
outreg2 using "Tab_SM3_1",excel dec(2) side

***mod2

xtmixed happiness c.lrgen i.gndr c.share_part i.weekend i.cntry  ///
        i.prepost_pand##i.govopp if final_samp == 1 || account:
outreg2 using "Tab_SM3_1",excel dec(2) side

********************************************************************************
***** table SM3-2
********************************************************************************

***mod1

xtmixed happiness c.lrgen i.gndr c.share_part i.weekend i.cntry ///
        i.monthyear_ i.govopp if final_samp == 1 || account:
outreg2 using "Tab_SM3_2",excel dec(2) side

***mod2

xtmixed happiness c.lrgen i.gndr c.share_part i.weekend i.cntry ///
        i.monthyear_##i.govopp if final_samp == 1 || account:
outreg2 using "Tab_SM3_2",excel dec(2) side


********************************************************************************
***** table SM4-1
********************************************************************************

/*see man_coding.do*/

********************************************************************************
***** table SM4-2
********************************************************************************

tab happy_fpp happy if final_samp==1,cell nof
	
tab group_pic_fpp group_pic if final_samp==1,cell nof


********************************************************************************
***** Tabella SM5_1
********************************************************************************

***mod1

xtmelogit happy c.lrgen i.gndr c.share_part i.weekend i.cntry  ///
        i.prepost_pand i.govopp if final_samp == 1 || account:
outreg2 using "Tab_SM5_1",excel dec(2) side
margins,at(prepost_pand=(0 1)) saving("happy_prepost_nointer") predict(mu fixedonly)

***mod2

xtmelogit group_pic c.lrgen i.gndr c.share_part i.weekend i.cntry  ///
        i.prepost_pand i.govopp if final_samp == 1 || account:
outreg2 using "Tab_SM5_1",excel dec(2) side
margins,at(prepost_pand=(0 1)) saving("group_prepost_nointer") predict(mu fixedonly)


********************************************************************************
***** Tabella SM5_2
********************************************************************************

***mod3

xtmelogit happy c.lrgen i.gndr c.share_part i.weekend i.cntry ///
        i.monthyear_ i.govopp if final_samp == 1 || account:
outreg2 using "Tab_SM5_2",excel dec(2) side
margins,at(monthyear_=(1(1)34)) saving("happy_month_nointer") predict(mu fixedonly)


***mod4 

xtmelogit group_pic c.lrgen i.gndr c.share_part i.weekend i.cntry  ///
        i.monthyear_ i.govopp if final_samp == 1 || account:
outreg2 using "Tab_SM5_2",excel dec(2) side
margins,at(monthyear_=(1(1)34)) saving("group_month_nointer") predict(mu fixedonly)

********************************************************************************
***** Tabella SM5_3
********************************************************************************

***mod5

xtmelogit happy c.lrgen i.gndr c.share_part i.weekend i.cntry  ///
        i.prepost_pand##i.govopp if final_samp == 1 || account:
outreg2 using "Tab_SM5_3",excel dec(2) side
margins,at(prepost_pand=(0 1) govopp=(0 1)) saving("happy_prepost_inter") predict(mu fixedonly)



***mod6

xtmelogit group_pic c.lrgen i.gndr c.share_part i.weekend i.cntry  ///
        i.prepost_pand##i.govopp if final_samp == 1 || account:
outreg2 using "Tab_SM5_3",excel dec(2) side
margins,at(prepost_pand=(0 1) govopp=(0 1)) saving("group_prepost_inter") predict(mu fixedonly)


********************************************************************************
***** Tabella SM5_4
********************************************************************************

***mod7

xtmelogit happy c.lrgen i.gndr c.share_part i.weekend i.cntry ///
        i.monthyear_##i.govopp if final_samp == 1 || account:
outreg2 using "Tab_SM5_4",excel dec(2) side
margins,at(monthyear_=(1(1)34) govopp=(0 1)) saving("happy_month_inter") predict(mu fixedonly)

***mod8

xtmelogit group_pic c.lrgen i.gndr c.share_part i.weekend i.cntry  ///
        i.monthyear_##i.govopp if final_samp == 1 || account:
outreg2 using "Tab_SM5_4",excel dec(2) side
margins,at(monthyear_=(1(1)34) govopp=(0 1))saving("group_month_inter") predict(mu fixedonly)


********************************************************************************
***** table SM6-1
********************************************************************************

*** mod1

xtmixed commnorm i.happy i.group_pic i.prepost_pand c.lrgen i.gndr ///
 c.share_part i.govopp i.weekend i.cntry if final_samp == 1  || account:
outreg2 using "Tab_SM6_1",excel dec(2) side

*** mod2

xtmixed commnorm i.happy##i.prepost_pand i.group_pic##i.prepost_pand ///
 c.lrgen i.gndr c.share_part i.govopp i.weekend i.cntry if final_samp == 1  || account:
outreg2 using "Tab_SM6_1",excel dec(2) side

*** mod3

xtmixed commnorm i.happy##i.monthyear_ i.group_pic##i.monthyear_ ///
c.lrgen i.gndr c.share_part i.govopp i.weekend i.cntry if final_samp == 1  || account:
outreg2 using "Tab_SM6_1",excel dec(2) side

*** margins mod3

margins,dydx(happy) at(monthyear_=(1(1)34)) saving("commnorm_happy_inter") 

margins,dydx(group_pic) at(monthyear_=(1(1)34)) saving("commnorm_group_inter")


********************************************************************************
***** table SM7-1
********************************************************************************

*** mod1

xtmelogit happy c.lrgen i.gndr c.share_part i.weekend i.cntry  ///
        i.govopp c.deaths_1m_sm if final_samp == 1 || account:
outreg2 using "Tab_SM7_1",excel dec(2) side
margins,at(deaths_1m_sm=(1(1)10)) saving("happy_deaths_nointer") predict(mu fixedonly)

*** mod2

xtmelogit group_pic c.lrgen i.gndr c.share_part i.weekend i.cntry  ///
        i.govopp c.deaths_1m_sm if final_samp == 1 || account:
outreg2 using "Tab_SM7_1",excel dec(2) side
margins,at(deaths_1m_sm=(1(1)10)) saving("group_deaths_nointer") predict(mu fixedonly)

*** mod3

xtmelogit happy c.lrgen i.gndr c.share_part i.weekend i.cntry  ///
        i.govopp##c.deaths_1m_sm if final_samp == 1 || account:
outreg2 using "Tab_SM7_1",excel dec(2) side
margins,at(deaths_1m_sm=(1(1)10) govopp=(0 1)) saving("happy_deaths_inter") predict(mu fixedonly)

*** mod4

xtmelogit group_pic c.lrgen i.gndr c.share_part i.weekend i.cntry  ///
        i.govopp##c.deaths_1m_sm if final_samp == 1 || account:
outreg2 using "Tab_SM7_1",excel dec(2) side
margins,at(deaths_1m_sm=(1(1)10) govopp=(0 1)) saving("group_deaths_inter") predict(mu fixedonly)

********************************************************************************
***** table SM8-1
********************************************************************************

*** mod1

xtmelogit mask_fpp c.lrgen i.gndr c.share_part i.weekend i.cntry  ///
        i.prepost_pand i.govopp if final_samp == 1 || account:
outreg2 using "TabNewRR",excel dec(2) side
margins,at(prepost_pand=(0 1)) saving("pre_post_1") predict(mu fixedonly)

*** mod2

xtmelogit mask_fpp c.lrgen i.gndr c.share_part i.weekend i.cntry  ///
        i.govopp if final_samp == 1 & prepost_pand ==1 || account:
outreg2 using "TabNewRR",excel dec(2) side 
margins,at(lrgen=(1(0.5)9)) saving("lrgen_2_post") predict(mu fixedonly)

********************************************************************************
***** table SM9-1
********************************************************************************

sum happiness neutral anger contempt disgust fear  sadness surprise if final_samp==1

foreach i of varlist anger contempt disgust fear happiness neutral sadness surprise {
recode `i' (0/0.4999999999=0 "No") (0.5/1=1 "Yes"),gen(`i'_binom)
}

fre happiness_binom neutral_binom anger_binom contempt_binom disgust_binom fear_binom  sadness_binom surprise_binom if final_samp==1

********************************************************************************
***** table SM10-1
********************************************************************************

/*
date		data_st
15-02-2020	21960
15-04-2020	22020
15-07-2020	22111
15-01-2021	22295
15-07-2021	22476
*/

mkspline data_st0 21960 data_st1 22020 data_st2 22111 data_st3 22295 data_st4 22476 data_st5 = data_st, marginal

*** mod1

xtmelogit happy c.lrgen i.gndr c.share_part i.weekend i.cntry ///
        data_st0-data_st5 i.govopp if final_samp == 1 || account:
outreg2 using "Tab_SM10_1",excel dec(2) side

*** mod2

xtmelogit group_pic c.lrgen i.gndr c.share_part i.weekend i.cntry ///
        data_st0-data_st5 i.govopp if final_samp == 1 || account:
outreg2 using "Tab_SM10_1",excel dec(2) side
	
********************************************************************************
***** table SM10-2
********************************************************************************

*** mod1

xtmelogit happy c.lrgen i.gndr c.share_part i.weekend i.cntry ///
        c.data_st0##i.govopp c.data_st1##i.govopp c.data_st2##i.govopp ///
		c.data_st3##i.govopp c.data_st4##i.govopp c.data_st5##i.govopp if final_samp == 1 || account:
outreg2 using "Tab_SM10_2",excel dec(2) side

*** mod2

xtmelogit group_pic c.lrgen i.gndr c.share_part i.weekend i.cntry ///
        c.data_st0##i.govopp c.data_st1##i.govopp c.data_st2##i.govopp ///
		c.data_st3##i.govopp c.data_st4##i.govopp c.data_st5##i.govopp if final_samp == 1 || account:
outreg2 using "Tab_SM10_2",excel dec(2) side
